<template>
  <basic-container>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-setting"></i> 账单管理
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <i class="el-icon-date"></i> 详情
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <avue-detail ref="form" v-model="form" :option="option"></avue-detail>
    <avue-crud ref="crud" :option="orderDetailOption" :data="orderDetailList"></avue-crud>
    <div>
      <el-button type="primary" @click="goBack">返 回</el-button>
    </div>
  </basic-container>
</template>

<script>
import { fetchInfo } from "../../api/bill/payable";
import { formOption } from "../../const/crud/bill/form_option/payable";
import { formOption as orderDetailOption } from "../../const/crud/bill/form_option/order_detail";
import { goBack } from "../../util/util";

export default {
  data() {
    return {
      form: {},
      option: formOption,
      orderDetailOption: orderDetailOption,
      orderDetailList: []
    };
  },
  computed: {},
  created() {},
  beforeRouteEnter(to, from, next) {
    next(vm => vm.queryData(vm.$route.query.res.billSn));
  },
  methods: {
    queryData(billSn) {
      fetchInfo({ billSn: billSn })
        .then(response => {
          this.form = Object.assign(
            {},
            response.data.data,
            response.data.data.orderInfo
          );
          this.orderDetailList = this.form.detailList;
        })
        .catch(() => {
          this.goBack();
        });
    },
    goBack(time = 1000) {
      goBack(this, time);
    }
  }
};
</script>

<style scoped lang="scss">
.crumbs {
  margin: 20px 10px;
}
</style>


